package com.pm.controller.file;

import com.pm.common.Response;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.file.DailyNewsType;
import com.pm.entity.vo.dept.DailyNewsTypeVo;
import com.pm.service.file.DailyNewsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "日常工作动态")
@UserLoginToken
@RestController
@RequestMapping("/dailyNewsType")
public class DailyNewsTypeController {
    @Autowired
    DailyNewsTypeService dailyNewsTypeService;

    @ApiOperation("新增接口")
    @PostMapping("/add")
    @ResponseBody
    @MyLog(value = "新增日常工作动态文件夹")
    public Response<Integer> add(DailyNewsType dailyNewsType) {
        Response<Integer> response = null;
        Integer result = dailyNewsTypeService.add(dailyNewsType);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }

    @ApiOperation("删除接口")
    @PostMapping("/remove")
    @ResponseBody
    @MyLog(value = "删除日常工作动态文件夹")
    public Response<Integer> remove(DailyNewsType dailyNewsType) {
        Response<Integer> response = null;
        Integer result = dailyNewsTypeService.remove(dailyNewsType);
        if (result > 0) {
            response = new Response<>(ExpCodeState.remove_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.remove_data_failed);
        }
        return response;
    }

    @ApiOperation("更新接口")
    @PostMapping("/update")
    @ResponseBody
    @MyLog(value = "编辑日常工作动态文件夹")
    public Response<Integer> update(DailyNewsType dailyNewsType) {
        Response<Integer> response = null;
        Integer result = dailyNewsTypeService.update(dailyNewsType);
        if (result > 0) {
            response = new Response<>(ExpCodeState.update_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.update_data_failed);
        }
        return response;
    }

    @ApiOperation("查询文件")
    @PostMapping("/getList")
    @ResponseBody
    public Response<DailyNewsTypeVo> getList(DailyNewsType dailyNewsType) {
        DailyNewsTypeVo result = dailyNewsTypeService.getListDailyNewsType(dailyNewsType);
        Response<DailyNewsTypeVo> res = new Response<>(ExpCodeState.query_data_success, result);
        return res;
    }
}
